import {
	Body,
	Controller,
	DefaultValuePipe,
	Delete,
	Get,
	Param,
	ParseIntPipe,
	Patch,
	Post,
	Query,
	UseGuards,
} from '@nestjs/common';
import { AdminUsersService } from './admin-users.service';
import { ApiBearerAuth, ApiHeader, ApiOperation, ApiTags } from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';
import { CreateAdminUserDto } from './dto/creater-user.dto';
import { UpdateAdminUserDto } from './dto/update-user.dto';
// import { Roles } from 'src/roles/roles.decorator';
// import { RoleEnum } from 'src/roles/roles.enum';
// import { AuthGuard } from '@nestjs/passport';
// import { RolesGuard } from 'src/roles/roles.guard';

@ApiBearerAuth() // 需要token
@UseGuards(AuthGuard('jwt'))
@ApiTags('管理员管理')
@ApiHeader({
	name: 'authoriation',
	required: true,
	description: 'token',
})
@Controller({
	path: 'adminUser',
	version: '1',
})
export class AdminUsersController {
	constructor(private readonly usersService: AdminUsersService) {}

	@ApiOperation({
		tags: ['创建管理员'],
		description: '创建管理员',
	})
	@Post()
	create(@Body() createAdminUserDto: CreateAdminUserDto) {
		return this.usersService.create(createAdminUserDto);
	}

	@Get()
	findAll() {
		return 'this.roleService.findAll()';
	}

	@ApiOperation({
		tags: ['查询管理员列表'],
		description: '查询管理员列表',
	})
	@Get('/getAdminUserList')
	findAdminUserList(
		@Query('pageNum', new DefaultValuePipe(1), ParseIntPipe) pageNum: number,
		@Query('pageSize', new DefaultValuePipe(10), ParseIntPipe) pageSize: number,
		@Query('keyword', new DefaultValuePipe('')) keyword: string,
	) {
		return this.usersService.findListByPage({
			pageNum,
			pageSize,
			keyword,
		});
	}

	@Get(':id')
	findOne(@Param('id') id: string) {
		return 'this.roleService.findOne(+id)';
	}

	@ApiOperation({
		tags: ['更新管理员'],
		description: '更新管理员',
	})
	@Patch(':userId')
	update(@Param('userId') userId: string, @Body() updateRoleDto: UpdateAdminUserDto) {
		return this.usersService.update(userId, updateRoleDto);
	}

	@Delete(':userId')
	remove(@Param('userId') userId: string) {
		return this.usersService.remove(userId);
	}
}
